package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
public class DishController {
    @Autowired
    DishService dishService;

    //菜品分页查询
    @GetMapping("/page")
    public Result page(DishPageQueryDTO dishPageQueryDTO) {
        log.info("分页查询，参数：{}", dishPageQueryDTO);
        PageResult page = dishService.page(dishPageQueryDTO);
        return Result.success(page);
    }

    //菜品新增
    @PostMapping
    public Result save(@RequestBody DishDTO dishDTO) {
        log.info("新增菜品，参数：{}", dishDTO);
        log.info("新增菜品，口味参数：{}", dishDTO.getFlavors());
        dishService.save(dishDTO);
        return Result.success();
    }

    //菜品批量删除
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids) {
        log.info("批量删除菜品，ids：{}", ids);
        dishService.delete(ids);
        return Result.success();
    }

    //菜品查询（根据Id）
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        log.info("查询菜品，id：{}", id);
        DishVO dishVO = dishService.getById(id);
        return Result.success(dishVO);

    }

    //菜品修改
    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO) {
        log.info("修改菜品，参数：{}", dishDTO);
        log.info("修改菜品，口味参数：{}", dishDTO.getFlavors());
        dishService.update(dishDTO);
        return Result.success();
    }

    //菜品查询（根据分类）
    @GetMapping("/list")
    public Result list(Integer categoryId) {
        log.info("查询菜品，分类id：{}", categoryId);
        List list = dishService.listBycategoryId(categoryId);

        return Result.success(list);
    }

    //菜品起售停售
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        dishService.permission(status, id);
        return Result.success();
    }


}
